<?php

namespace App\Middleware;

use Closure;

class CrossMiddleware
{
    /**
     * @param $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $origin = $request->header('Origin');

        header('Access-Control-Allow-Origin: ' . $origin);
        header("Access-Control-Allow-Credentials: true");
        header("Access-Control-Allow-Methods: *");
        header("Access-Control-Allow-Headers: Content-Type,Token,Access-Token,Authorization");
        header("Access-Control-Expose-Headers: *");

        if ($request->isMethod('OPTIONS')) {
            return response('', 200);
        }

        //windfnn 图片访问链接
        $url = $request->getUri();
        if(str_contains($url,'image.php'))
        {
            $image =  app('Modules\Sys\Http\Controllers\ImageController');
            return $image->get($request);
        }

        return $next($request);
    }
}
